import asyncio
import websockets

async def test_websocket():
    try:
        async with websockets.connect("ws://127.0.0.1:8765") as websocket:
            print("已连接到WebSocket服务端")
            # 可以在这里添加更多的测试逻辑，比如发送和接收消息
            message = await websocket.recv()
            print(f"收到消息: {message}")
    except Exception as e:
        print(f"连接出错: {e}")

asyncio.get_event_loop().run_until_complete(test_websocket())
